import { WorkflowStatus } from '@/utils/api/workflow/list/type';
import { defineComponent, computed, type PropType } from 'vue';
interface WorkflowStatusProps {
    status: WorkflowStatus;
}

const statusTextMap: Map<WorkflowStatus, string> = new Map([
    [WorkflowStatus.Runnable, '审核中'],
    [WorkflowStatus.Suspended, '已暂停'],
    [WorkflowStatus.Complete, '已完成'],
    [WorkflowStatus.Terminated, '已终止']
]);

const statusColorMap: Map<WorkflowStatus, string> = new Map([
    [WorkflowStatus.Runnable, 'blue'],
    [WorkflowStatus.Suspended, 'orange'],
    [WorkflowStatus.Complete, 'cyan'],
    [WorkflowStatus.Terminated, 'red']
]);

const WorkflowStatusComponent = defineComponent({
    name: 'WorkflowStatusComponent', // 组件名
    props: {
        status: {
            type: Number as PropType<WorkflowStatus>,
            default: 0
        }
    },
    setup(props: WorkflowStatusProps) {
        const statusText = computed(() => {
            return statusTextMap.get(props.status);
        });
        const statusStyle = computed(() => {
            return {
                color: statusColorMap.get(props.status)
            };
        });
        return () => (
            <div style={statusStyle.value}>
                {statusText.value}
            </div>
        );
    }
});
export default WorkflowStatusComponent;